#ifndef SIMULATION_RUNNER_H
#define SIMULATION_RUNNER_H

#include <QtCore/QObject>

QT_BEGIN_NAMESPACE
class QTimer;
QT_END_NAMESPACE

namespace wfnet
{
class WfNet;
}

namespace swp
{

class SimulationRunner : public QObject
{
    Q_OBJECT

    enum State
    {
        Idle,
        Running,
        Paused
    };

public:
    static SimulationRunner* getInstance();
    static void destroy();

    void simulate(wfnet::WfNet* net, int repetitions, int timeout);

signals:
    void simulationStarted();
    void simulationPaused();
    void simulationContinued();
    void simulationFinished(bool interrupted);

private:
    SimulationRunner();
    ~SimulationRunner();

public slots:
    void nextStep();
    void previousStep();
    void pause();
    void continueSimulation();
    void stop();

private slots:
    void interrupt();
    void emitFinished();

private:
    wfnet::WfNet* m_net;
    State m_state;
    QTimer* m_timeoutTimer;
};

} // namespace swp

#endif
